package com.mujin.keji.collectionsystem.module.sign.viewmodel;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;
import android.content.Context;

import com.mujin.keji.collectionsystem.base.BaseDto;
import com.mujin.keji.collectionsystem.module.sign.dto.SignDetailDto;
import com.mujin.keji.collectionsystem.module.sign.dto.SignDto;
import com.mujin.keji.collectionsystem.module.sign.respository.ISignDetailRepository;
import com.mujin.keji.collectionsystem.module.sign.respository.ISignRepository;
import com.mujin.keji.collectionsystem.module.sign.respository.SignDetailRepository;
import com.mujin.keji.collectionsystem.module.sign.respository.SignRepository;
import com.mujin.keji.collectionsystem.module.sign.vo.SignDetailVo;
import com.mujin.keji.collectionsystem.module.sign.vo.SignVo;

/**
 * 签到viewmodel
 *
 * @author weishixiong
 * @Time 2018-04-28
 */
public class SignViewModel extends ViewModel {
    private LiveData<BaseDto<SignDto>> signLiveData;
    private LiveData<BaseDto<SignDetailDto>> signDetailLiveData;
    private ISignRepository signRepository;
    private ISignDetailRepository signDetailRepository;

    public LiveData<BaseDto<SignDto>> getSignLiveData(String signAddress, String signDate, String source, Context context) {
        sign(signAddress, signDate, source, context);
        return signLiveData;
    }


    public LiveData<BaseDto<SignDetailDto>> getSignDetailLiveData(String date, Context context) {
        signDetail(date, context);
        return signDetailLiveData;
    }

    /**
     * 签到
     *
     * @param signAddress
     * @param signDate
     * @param source
     */
    private void sign(String signAddress, String signDate, String source, Context context) {
        SignVo vo = new SignVo(signAddress, signDate, source);
        signRepository = new SignRepository();
        this.signLiveData = signRepository.sign(vo, context);
    }

    /**
     * 签到详情
     *
     * @param date
     */
    private void signDetail(String date, Context context) {
        signDetailRepository = new SignDetailRepository();
        SignDetailVo vo = new SignDetailVo(date);
        this.signDetailLiveData = signDetailRepository.signDetail(vo, context);
    }
}
